<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let input = `3 4 5 6 7 3 4 5 6 7 8 5 6`
        //初始化-解析输入值
        input = input.split(' ')
        console.log(input);

        //初始化存储数组与牌组
        let mylist = new Array(13).fill(0)
        let pai_list = ['3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A', '2'];
        input.forEach((v) => {//把发牌员给的牌存入mylist
            let v_code = v.charCodeAt()
            let t_code = '3'.charCodeAt()
            if (v_code - t_code >= 0 && v_code - t_code <= 7) {
                mylist[parseInt(v_code - t_code)]++;
            } else {
                switch (v) {
                    case 'J':
                        mylist[8]++
                        break;
                    case 'Q':
                        mylist[9]++
                        break;
                    case 'K':
                        mylist[10]++
                        break;
                    case 'A':
                        mylist[11]++
                        break;
                    case '2':
                        mylist[12]++
                        break;
                    default:
                        break;
                }
            }
        })

        let right = 0;
        let left = 0;
        let res = []

        //滑动找顺子
        while (left <= 7) {

            if (mylist[left] === 0) {
                left++;
                right = left
                continue;
            }
            let str = ''
            while (mylist[right] != 0) {
                str += pai_list[right];
                right++;
            }
            let str_len = str.length

            if (str_len >= 5) {//判断牌长度是否合法
                res.push(str)
                let j = left;
                while (j < right) {
                    mylist[j]--;
                    j++
                }
                right=left;//可能有两个顺子是相同的，所以得再查一次

            } else {
                left++;//left开头没有合法的顺子，查下一个
                right=left
            }
        }
        console.log(...res);




    </script>
</body>

</html>